<template>
  <CompOperate
      :field="field"
      :designer="designer"
      :design-state="designState"
      :parent-list="parentList"
      :parent-widget="parentWidget"
      :sub-form-row-id="subFormRowId"
      :sub-form-row-index="subFormRowIndex"
      :sub-form-col-index="subFormColIndex"
      :index-of-parent-list="indexOfParentList"
      :display-style="field.options.displayStyle"
  >
    <div class="scene-window-call-current-patient-widget" :style="getStyle('area')">
      <div class="area-inside">

        <div class="head" :style="getStyle('head')">{{ optionsInfo['title']['connect'] }}</div>
        <div class="list-area" :key="scrollReset">
          <vue-seamless-scroll
              class="scroll"
              :data="data"
              :hoverStop="false"
              @ScrollEnd="handleScrollEnd"
              :class-option="optionCallPatientList"
              ref="drug-scroll"
          >
            <div v-for="(items, index) in data" :key="index">
              <div class="patient-item" :style="getStyle('list')">
                <template v-for="(item) in optionsInfo['windowColOption']">
                  <template v-if="(item.value) !=='window'&&(item.value) !=='patient'">
                    <div class="desc-item" :class="item.value" :style="setFlex(item,'list')">
                      {{ item.label }}
                    </div>
                  </template>

                  <template v-if="(item.value) ==='window'">
                    <div class="desc-item win-number" :class="item.value" :style="setFlex(item,'list')">窗口3</div>
                  </template>

                  <template v-if="(item.value) ==='patient'">
                    <div class="desc-item patient-info" :class="item.value" :style="setFlex(item,'list')">
                      <span
                          class="patient-orderNo"
                          :class="getClassName"
                          :style="getStyle('orderNo')"
                      >
                        {{ items }}
                      </span>
                      <span class="patient-name">秦时明月</span>
                    </div>
                  </template>
                </template>
              </div>
            </div>
          </vue-seamless-scroll>
        </div>
      </div>
    </div>
  </CompOperate>
</template>

<script>
import {NoticeBar, Swipe, SwipeItem} from "vant";
import emitter from "@/utils/designer/emitter";
import {pxToVw} from '@/utils/common';
import ScrollY from '@c/public/seamlessScroll/ScrollY.vue';
import ScrollX from '@c/public/seamlessScroll/ScrollX.vue';
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import {buildParentApi} from "@/utils/designer/util";
import vueSeamlessScroll from 'vue-seamless-scroll';
import {setWindowDeptInfo} from "@/store/modules/actions";
import {v4 as uuid} from 'uuid';

export default {
  name: "scene-window-call-current-patient-1080-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    ScrollX,
    CompOperate,
    NoticeBar,
    Swipe,
    SwipeItem,
    ScrollY,
    vueSeamlessScroll
  },

  props: {
    widget: Object,
    devType: {
      type: Boolean,
      default: false,
    },
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },
    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
    //prop传入的表单JSON配置
    parentApi: {
      type: Object,
      default: () => buildParentApi()
    },
  },

  data() {
    return {
      optionsInfo: Object(),
      data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
      header: require("@a/images/design/header.jpeg"),
      pause: require("@a/images/design/pause.png"),
    }
  },

  computed: {
    // 模板配置行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case 'area':
            Reflect.set(Obj, 'height', pxToVw(info.areaHeight));
            return Obj;
          case 'head':
            Reflect.set(Obj, 'fontWeight', (info['title']['fontWeight']));
            Reflect.set(Obj, 'fontSize', pxToVw(info['title']['fontSize']));
            Reflect.set(Obj, 'color', (info['title']['color']));
            Reflect.set(Obj, 'background', (info['title']['background']));
            return Obj;
          case 'list':
            Reflect.set(Obj, 'fontSize', pxToVw(info['list']['fontSize']));
            return Obj;
          case 'orderNo':
            Reflect.set(Obj, 'color', (info['list']['orderNoColor']));
            Reflect.set(Obj, 'background', (info['list']['orderNoBackground']));
            return Obj;
          case 'patient':
            Reflect.set(Obj, 'fontWeight', (info['list']['orderNoFontWeight']));
            return Obj;
        }
      }
    },

    // 设置宽度和字号
    setFlex() {
      return function (item, val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case "list":
            Reflect.set(Obj, 'fontWeight', (info['list']['orderNoFontWeight']));
            Reflect.set(Obj, "flex", (item.flex) || 1);
            return Obj;
        }
      }
    },

    // 药品公示向上的滚动
    optionCallPatientList() {
      let {scrollNumber} = (this.optionsInfo);
      return {
        step: [1, 1.5, 2, 2.5, 3][0], // 数值越大速度滚动越快
        hoverStop: true,
        limitMoveNum: scrollNumber, // 开始无缝滚动的数据量 this.dataList.length
        direction: 1 // 0向下 1向上 2向左 3向右
      };
    },

    scrollReset() {
      let {scrollNumber} = (this.optionsInfo);
      if (scrollNumber) {
        return uuid()
      }
    },

    getClassName() {
      let {list} = (this.optionsInfo);
      if (!(list && (list.orderNoBackgroundShown))) {
        return 'background-no'
      }
    }

  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    executeMethod(key, data) {
      switch (key) {
        case "roomDoctorInfo":
          console.log(`医生-患者-信息-${data}`);
          this.$store.dispatch('setRoomDoctorInfo', this.$lodash.cloneDeep(data))
          break
        case "roomDeptInfo":
          console.log(`科室诊室信息-${data}`)
          this.$store.dispatch('setWindowDeptInfo', this.$lodash.cloneDeep(data))
          break
      }
    },

    // 滚动结束的回调
    handleScrollEnd() {
    },
  },


  watch: {
    field: {
      handler: function (val) {
        let key = (val.options.config)
        this.optionsInfo = (val.options[key]);
      },
      deep: true,
      immediate: true
    }
  },

  destroyed() {
    this.unregisterFromRefList();
  },

};
</script>

<style lang="scss" scoped>
.scene-window-call-current-patient-widget {
  color: #333;
  height: 150px;
  font-size: 40px;
  overflow: hidden;
  padding: 0 30px;
  box-sizing: border-box;
  background: transparent;

  .area-inside {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    border-radius: 18px;
    overflow: hidden;
    background: white;
    padding: 22px;

    .head {
      width: 100%;
      background: #0059B3;
      border-radius: 20px;
      padding: 15px 20px;
      font-weight: 500;
      font-size: 60px;
      line-height: 84px;
      color: #FDFDFD;
      @include singleEllipsis(100%);
      text-align: center;
    }

    .list-area {
      display: flex;
      overflow: hidden;
      font-weight: normal;
      flex-direction: column;

      .patient-item {
        display: flex;
        align-items: center;
        align-self: center;
        height: 108px;
        flex-direction: row;
        font-size: 50px;
        color: #333333;
        padding: 0 70px;
        border-bottom: 1px rgba(216, 216, 216, 1) solid;

        .desc-item {
          flex: 1;
          white-space: nowrap;
          flex-wrap: nowrap;
        }

        .please {
          flex: 0.8;
        }

        .patient-info {
          flex: 3.5;
          color: rgba(0, 89, 179, 1);

          .patient-orderNo {
            display: inline-flex;
            border-radius: 12px;
            overflow: hidden;
            justify-content: center;
            min-width: 60px;
            padding: 8px 14px;
            margin-right: 16px;
            color: white;
            background: rgba(0, 89, 179, 1);
          }

          .background-no {
            background: transparent !important;
            color: rgba(0, 89, 179, 1);
          }
        }

        .win-number {
          flex: 1.5;
          font-weight: 560;
          color: rgba(0, 89, 179, 1);
        }
      }
    }
  }
}
</style>